package com.seezoon.application.tcp.executor.press.cases;

import com.seezoon.infrastructure.tcp.codec.JT808;
import com.seezoon.infrastructure.tcp.codec.JTMessage;
import com.seezoon.infrastructure.tcp.codec.JTSerialization;
import com.seezoon.infrastructure.tcp.jt808.JT0002;
import com.seezoon.infrastructure.tcp.jt808.JT8001;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

/**
 * Scope.Benchmark 一个进程用一个
 */
@State(Scope.Benchmark)
@Slf4j
public class HeartBeat extends Auth {


    @Benchmark
    public void execute() {
        JT0002 request = new JT0002();
        // 终端心跳消息体为空，不需要设置任何字段
        byte[] encode = JTSerialization.encode(request);
        JTMessage jtMessage = new JTMessage();
        jtMessage.setMsgId(JT808.终端心跳);
        jtMessage.setMsgProperties(encode.length);
        jtMessage.setSerialNo(serialNo);
        jtMessage.setMsgSerialNo(client.nextSequence(serialNo));
        jtMessage.setBody(Unpooled.wrappedBuffer(encode));
        JT8001 response = client.send(jtMessage, JT8001.class);
    }


}
